package com.rpframework.utils

import com.gexin.rp.sdk.base.impl.ListMessage
import com.gexin.rp.sdk.base.impl.Target
import com.gexin.rp.sdk.http.IGtPush
import com.gexin.rp.sdk.template.NotificationTemplate
import java.util.*

//采用"Java SDK 快速入门"， "第二步 获取访问凭证 "中获得的应用配置，用户可以自行替换
private val appId = "BfRNVQ7fGy8oMT0O7WXMU2"
private val appKey = "mjiyNY9r0j8YZs1lWJLjD"
private val masterSecret = "ZpeJEoBomn5jwAiZNTagM8"

var CID = "3726512377f68c189046b3b331efd7f0"

var CID1 = "3726512377f68c189046b3b331efd7f0"
var CID2 = ""
//别名推送方式
// static String Alias1 = "";
// static String Alias2 = "";
var host = "http://sdk.open.api.igexin.com/apiex.htm"

fun main(args: Array<String>) {
    // 配置返回每个用户返回用户状态，可选
    System.setProperty("gexin_pushList_needDetails", "true")
    // 配置返回每个别名及其对应cid的用户状态，可选
    // System.setProperty("gexin_pushList_needAliasDetails", "true");
    val push = IGtPush(host, appKey, masterSecret)
    // 通知透传模板
    val template = notificationTemplateDemo()
    val message = ListMessage()
    message.data = template
    // 设置消息离线，并设置离线时间
    message.isOffline = true
    // 离线有效时间，单位为毫秒，可选
    message.offlineExpireTime = (24 * 1000 * 3600).toLong()
    // 配置推送目标
    val targets = ArrayList<Target>()
    val target1 = Target()
    val target2 = Target()
    target1.setAppId(appId)
    target1.setClientId(CID1)
    //     target1.setAlias(Alias1);
    target2.setAppId(appId)
    target2.setClientId(CID2)
    //     target2.setAlias(Alias2);
    targets.add(target1)
    //targets.add(target2)
    // taskId用于在推送时去查找对应的message
    val taskId = push.getContentId(message)
    val ret = push.pushMessageToList(taskId, targets)
    println(ret.response.toString())
}

fun notificationTemplateDemo(): NotificationTemplate {
    val template = NotificationTemplate()
    // 设置APPID与APPKEY
    template.setAppId(appId)
    template.setAppkey(appKey)
    // 设置通知栏标题与内容
    template.setTitle("标题")
    template.setText("内容")
    // 配置通知栏图标
    template.setLogo("icon.png")
    // 配置通知栏网络图标
    template.setLogoUrl("")
    // 设置通知是否响铃，震动，或者可清除
    template.setIsRing(true)
    template.setIsVibrate(true)
    template.setIsClearable(true)
    // 透传消息设置，1为强制启动应用，客户端接收到消息后就会立即启动应用；2为等待应用启动
    template.setTransmissionType(1)
    // template.transmissionContent = "{"title":"标题", "content":"内容", "payload":{"type":1}}"
    template.transmissionContent = """{"title":"标题", "content":"内容", "payload":{"type":1}}"""
    return template
}